package com.googlecode.hmvc4gwt.example.hmvcblog.server.repository.blog.entry.comment;

import java.util.List;

import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.blog.BlogEntry;
import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.blog.BlogEntryComment;

@Transactional
public class BlogEntryCommentRepository extends JpaDaoSupport implements
		IBlogEntryCommentRepository {
	
	public void addBlogEntryComment(BlogEntryComment blogComment) {		
		getJpaTemplate().persist(blogComment);
	}

	@SuppressWarnings("unchecked")
	public List<BlogEntryComment> findByBlogEntry(BlogEntry blogEntry) {		
		return getJpaTemplate().findByNamedQuery("BlogEntryComment.findByBlogEntry", blogEntry);		
	}

	public BlogEntryComment findById(int blogCommentId) {
		return getJpaTemplate().getEntityManager().find(BlogEntryComment.class, blogCommentId);
	}

	public void removeBlogEntryComment(BlogEntryComment blogComment) {
		getJpaTemplate().getEntityManager().remove(blogComment);
	}

	public void updateBlogEntryComment(BlogEntryComment blogEntryComment) {		
		getJpaTemplate().getEntityManager().merge(blogEntryComment);
	}
}
